//index.js
var videoData = require("../../data/data.js");
Page({
  data: {
    curr_id: '',
    items:[]
  },
  // 初始化
  onLoad:function(){
    this.setData({
      items: videoData.videoData
    })
  },
  
  //转发功能
  onShareAppMessage: function (res) {
    return {
      title: '',
      path: '/pages/index/index',
      success: function (res) {
        // 转发成功
      },
      fail: function (res) {
        // 转发失败
      }
    }
  },
  //点击事件，点击跳转到搜索页面
  search_head: function () {
    wx.navigateTo({
      url: '../search/search'
    })
  },
  //列表详情页跳转
  newUrl : function(u){
    var that = this;
    var id = u.target.id;
    wx.navigateTo({
      url: "../details/details?id=" + id    
    })
     
      
  },
  // 视频展开收起按钮
  closeOrOpen: function (e) {
    var that = this;
    var id = e.target.id;
    for (var i = 0; i < that.data.items.length; i++) {
      if (id == that.data.items[i].id) {
        var isFold = 'items[' + i + '].isFold';
        var Fold = that.data.items[i].isFold;
        that.setData({
          [isFold]: !Fold
        })
      }
    }
  },   
  onReady: function () {
    this.videoContext = wx.createVideoContext('myVideo')
  },
  videoPlay(e) {
    this.setData({
      curr_id: e.currentTarget.dataset.id,
    })
    this.videoContext.play()
  },
  
})
